package com.kongwg.java;

import org.junit.Test;

import java.util.*;

/**
 * @author kongwg
 * @create 2020-12-17 9:55
 */
public class GenericTest {

    @Test
    public void test() {
        ArrayList list = new ArrayList();

        list.add(78);
        list.add(76);
        list.add(29);
        list.add(89);
        list.add(79);
        list.add("Tom");

        for (Object obj : list) {
            int stuScore = (Integer) obj;

            System.out.println(stuScore);
        }

    }

    //使用泛型
    @Test
    public void test2() {
        ArrayList<Integer> list = new ArrayList<>();

        list.add(79);
        list.add(99);
        list.add(79);
        list.add(29);
        list.add(39);
        //不能添加字符串
//            list.add("Tom");

        for (Integer score : list) {
            int stuScore = score;
            System.out.println(stuScore);
        }

        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {

            int integer = iterator.next();


        }
    }

    @Test
    public void test3() {
        HashMap<String, Integer> map = new HashMap<>();

        map.put("Tom",18);
        map.put("Rose",28);
        map.put("Monica",78);

        Set<Map.Entry<String, Integer>> set = map.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator = set.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> entry = iterator.next();
            System.out.println(entry.getKey() + "---" + entry.getValue());


        }

    }
}
